package com.gwamcc.adduser.service.serviceimpl;

import com.gwamcc.adduser.dao.OperateDao;
import com.gwamcc.adduser.service.IOperateService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2020/6/10.
 */
@Service
public class OperateServiceImpl implements IOperateService {

//    @Resource
//    protected OperateDao operateDao;

    private static Logger log = LoggerFactory.getLogger(OperateServiceImpl.class.getName());

    /**
     * 新增保存
     * @param empid
     * @param account
     * @param name
     * @param orgid
     * @param orgname
     * @return
     */
    @Override
    public Object addSave(String empid, String account, String name, String orgid, String orgname){
//        try{
//            operateDao.addEmployee(empid, account, name);
//            //组织暂时统一为：外包人员工作组。故此处先注释掉，不做新增
////            operateDao.addOrganize(orgid, orgname, orgid, orgid);
//            operateDao.addOrganizeEmployee(empid, orgid, orgid);
//            operateDao.addPartTimeJob(orgid, empid);
//        } catch (Exception e) {
//            log.error("=========== 新增人员机构信息错误 ==========="+e.getMessage());
//            return "Emp_ID已存在，请重新输入！";
//        }
        return "人员信息保存成功！";
    }

    /**
     * 删除；逻辑删除--dr置为1
     * @param empid
     * @param orgid
     * @return
     */
    @Override
    public Object delete(ArrayList<String> empid, ArrayList<String> orgid) {
//        operateDao.delEmployee(empid);
//        operateDao.delOrganize(orgid);
//        operateDao.delOrganizeEmployee(empid);
//        operateDao.delPartTimeJob(empid);
        return "人员信息删除成功！";
    }

    /**
     * 更新
     * @param empid
     * @param account
     * @param name
     * @param orgid
     * @param orgname
     * @param orgcode
     * @return
     */
    @Override
    public Object update(String empid, String account, String name, String orgid, String orgname, String orgcode) {
//        operateDao.updEmployee(empid, account, name);
//        operateDao.updOrganize(orgid, orgname, orgcode);
        //organize和employee绑定的分别是employee和organize主键，故两个表不可以更新
//        operateDao.updPartTimeJob(empid);
//        operateDao.updOrganizeEmployee(empid);
        return "人员信息更新成功！";
    }

    /**
     * 模糊查询
     * @param whereSql
     * @return
     */
    @Override
    public List<Map<String, Object>> query(String whereSql) {
        //判断模糊查询条件是否都为数字
//        boolean bool = isDigit(whereSql);
//        List<Map<String, Object>> list = null;
//        if(bool) {
//           list = operateDao.queryByEmpid(whereSql);
//           if(list==null || list.size()==0) {
//                list = operateDao.queryByOrgid(whereSql);
//           }
//        }
//        if(list==null || list.size()==0) {
//            list = operateDao.queryByName(whereSql);
//        }
//        if(list==null || list.size()==0) {
//            list = operateDao.queryByAccount(whereSql);
//        }
//        if(list==null || list.size()==0) {
//            list = operateDao.queryByOrgname(whereSql);
//        }
        return null;
    }

    /**
     * 判断字符串中是否都为数字
     * @param str
     * @return
     */
    public boolean isDigit(String str) {
        return str.matches("[0-9]{1,}");
    }
}
